package de.vocabulary.server.persistence;

import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;

import com.sleepycat.bind.tuple.TupleBinding;

import de.vocabulary.server.persistence.BerkeleyDbDatabaseTupleBinding;
import de.vocabulary.server.persistence.BerkeleyDbEnvironment;


public class DBTestTupleBinding {
    

    @Rule
    public TemporaryFolder folder = new TemporaryFolder();
    
	@Test
	public void dbTest() throws Exception {
		
		BerkeleyDbEnvironment dbEnv = new BerkeleyDbEnvironment(folder.newFolder().getAbsolutePath(), false, true);
		BerkeleyDbDatabaseTupleBinding db = new BerkeleyDbDatabaseTupleBinding(dbEnv, "test", false, true, TupleBinding.getPrimitiveBinding(String.class));
		
		db.put("1", "one");
		db.put("2", "two");
		
		db.close();
		
		BerkeleyDbDatabaseTupleBinding dbRead = new BerkeleyDbDatabaseTupleBinding(dbEnv, "test", false, true, TupleBinding.getPrimitiveBinding(String.class));
		
		for (String key : dbRead.getKeys()) {
			System.out.println(key + "- " + dbRead.get(key));
		}
		
		dbRead.close();
		dbEnv.close();
		
	}
}
